package _09Stream流综合案例;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Demo {
    public static void main(String[] args) {
        ArrayList<String> list1 = new ArrayList<>();
        Collections.addAll(list1,"令狐冲","风清扬","任我行","东方不败","岳不群");
        ArrayList<String> list2 = new ArrayList<>();
        Collections.addAll(list1,"马云","李彦宏","刘强东","马化腾","马保国");

        Stream<String> stream1 = list1.stream();
        Stream<String> stream2 = list2.stream();


        Stream<String> newStream1 = stream1.filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return s.length() == 3;
            }
        }).limit(3);


        Stream<String> newStream2 = stream2.filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return s.startsWith("马");
            }
        }).skip(2);
        List<Person> collect = Stream.concat(newStream1, newStream2).map(new Function<String, Person>() {
            @Override
            public Person apply(String s) {
                return new Person(s);
            }
        }).collect(Collectors.toList());


        for (Person person : collect) {
            System.out.println(person);
        }

    }
}
